home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / misc / shokdial / errors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-13  |  2.3 KB  |  84 lines

  1. /* Functions:                                  */
  2. /* ----------                                        */
  3. /* checkok         -- Checks modem for 'OK'             */
  4. /* checkpoints     -- Checks for conflicting options            */
  5. /* check_for_error -- makes sure all bytes were written        */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <unistd.h>
  10. #include "colors.h"
  11.  
  12. #define ERROR -1
  13.  
  14. extern int conf; /* Do we read phone numbers from a config file?          */
  15. extern int rand; /* Do we use random (as opposed to sequential) scanning? */
  16. extern int useStdin; /* Do we read numbers from standard input?           */
  17.  
  18. void checkoptions()
  19. {
  20.   if (useStdin == 1 && (rand == 1 || conf == 1)) {
  21.      printf("You can't specify to either %srandomly%s select numbers, "
  22.             "read numbers\nfrom a %sconfig file%s, or to read numbers "
  23.             "from %sstandard input%s all at\nthe sametime.\n\n",
  24.             BOLDRED, NORMAL, BOLDCYAN, NORMAL, BOLDGREEN, NORMAL);
  25.  
  26.      exit(ERROR);
  27.   }
  28.  
  29.   if (rand == 1 && conf == 1) {
  30.      printf("You can't specify to either %srandomly%s select numbers, "
  31.             "read numbers\nfrom a %sconfig file%s, or to read numbers "
  32.             "from %sstandard input%s all at\nthe sametime.\n\n",
  33.             BOLDRED, NORMAL, BOLDCYAN, NORMAL, BOLDGREEN, NORMAL);
  34.  
  35.      exit(ERROR);
  36.   }
  37. }
  38.  
  39. void check_for_error(char *LogFile, int fd, int num, char *s)
  40. {
  41.   FILE *logfile;
  42.  
  43.   if ((logfile = fopen(LogFile, "a")) == NULL) {
  44.      perror("fopen");
  45.      hangup(), close(fd), exit(ERROR);
  46.   }
  47.  
  48.   if (num == ERROR) {
  49.      fprintf(stderr, "%sError%s while trying to %s%s%s to/from the modem.\n", 
  50.                BOLDRED, NORMAL, BOLDCYAN, s, NORMAL);
  51.      fprintf(logfile, "Error while trying to %s to/from the modem.\n", s);
  52.      fflush(logfile);
  53.  
  54.      hangup(), close(fd), exit(ERROR);
  55.   }
  56.   
  57.   fclose(logfile);
  58. }  
  59.  
  60. int checkok(char *LogFile, int fd, char *buf, char *s)
  61. {
  62.   FILE *logfile;
  63.  
  64.   if ((logfile = fopen(LogFile, "a")) == NULL) {
  65.      perror("fopen");
  66.      hangup(), close(fd), exit(ERROR);
  67.   }
  68.  
  69.   if ((strstr(buf, "OK")) == NULL) {
  70.      #if BEEP == WANTBEEP
  71.      putchar('\a');
  72.      #endif
  73.  
  74.      fprintf(logfile, "The modem didn't give me an \"OK\" when %s. Aborting.\n", s);
  75.      fprintf(stderr, "The modem didn't give me an \"%sOK%s\" when %s%s%s. %sAborting%s.\n", 
  76.          BOLDCYAN, NORMAL, PINK, s, NORMAL, BOLDRED, NORMAL);
  77.      fflush(logfile);
  78.     
  79.      return 1;
  80.   }
  81.  
  82.   return 0;
  83. }
  84.